package co.fitstart.entity.user;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import com.alibaba.fastjson.annotation.JSONField;
import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.site.Site;

/**
 * 电话资源
 * @author haiyan_xiao
 *
 */
@Entity
@Table(name = "telephone_resource")
@PersistentFormat
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class TelephoneResource {
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private User user;
    
    /** 门店 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Site site;
    
    /** 首次接待人 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Principal receptionist;
    
    /** 渠道 */
    private String channel;
    
    /** 名单收集日期 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date collectDate;
    
    /** 电话拨打预约记录 */
    @OneToMany(mappedBy = "telephoneResource", fetch = FetchType.LAZY)
    @Where(clause = "is_disabled = 0")
    @OrderBy("create_time DESC")
    @JSONField(serialize = false)
    private List<TelephoneRecord> telephoneRecords;
    
    /** 是否到店 */
    private boolean experienced;
    
    /** 未到店原因 */
    private String breakReason;
    
    /** 创建时间 */
    private Date createTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    public TelephoneResource() {
        
    }
    
    public TelephoneResource(User user, Site site, Principal receptionist, Date collectDate) {
        this.user = user;
        this.site = site;
        this.receptionist = receptionist;
        this.collectDate = collectDate;
        this.experienced = false;
        this.createTime = new Date();
        this.disabled = false;
    }
    
    /**
     * 
     * @param user
     * @return
     */
    public TelephoneResource initilize(User user) {
        this.user = user;
        this.experienced = false;
        this.createTime = new Date();
        this.disabled = false;
        
        return this;
    }
    
    /**
     * 
     * @param site
     * @return
     */
    public TelephoneResource editSite(Site site) {
        this.site = site;
        
        return this;
    }
    
    public TelephoneResource editReceptionist(Principal receptionist) {
        this.receptionist = receptionist;
        
        return this;
    }
    
    /**
     * 
     * @param breakReason
     * @return
     */
    public TelephoneResource editBreakReason(String breakReason) {
        this.breakReason = breakReason;
        
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return the site
     */
    public Site getSite() {
        return site;
    }

    /**
     * @param site the site to set
     */
    public void setSite(Site site) {
        this.site = site;
    }

    /**
     * @return the receptionist
     */
    public Principal getReceptionist() {
        return receptionist;
    }

    /**
     * @param receptionist the receptionist to set
     */
    public void setReceptionist(Principal receptionist) {
        this.receptionist = receptionist;
    }

    /**
     * @return the channel
     */
    public String getChannel() {
        return channel;
    }

    /**
     * @param channel the channel to set
     */
    public void setChannel(String channel) {
        this.channel = channel;
    }

    /**
     * @return the collectDate
     */
    public Date getCollectDate() {
        return collectDate;
    }

    /**
     * @param collectDate the collectDate to set
     */
    public void setCollectDate(Date collectDate) {
        this.collectDate = collectDate;
    }

    /**
     * @return the telephoneRecords
     */
    public List<TelephoneRecord> getTelephoneRecords() {
        return telephoneRecords;
    }

    /**
     * @param telephoneRecords the telephoneRecords to set
     */
    public void setTelephoneRecords(List<TelephoneRecord> telephoneRecords) {
        this.telephoneRecords = telephoneRecords;
    }

    /**
     * @return the experienced
     */
    public boolean isExperienced() {
        return experienced;
    }

    /**
     * @param experienced the experienced to set
     */
    public void setExperienced(boolean experienced) {
        this.experienced = experienced;
    }

    /**
     * @return the breakReason
     */
    public String getBreakReason() {
        return breakReason;
    }

    /**
     * @param breakReason the breakReason to set
     */
    public void setBreakReason(String breakReason) {
        this.breakReason = breakReason;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
